package system.student.funtion.exhibition.teacherfunction.impl;

import system.student.entity.signin.SignInRecord;
import system.student.entity.signin.SignInTask;
import system.student.funtion.exhibition.teacherfunction.SignInService;
import system.student.mapper.SignInTaskMapper;
import system.student.util.LogRecordUtil;
import system.student.util.MapperUtil;

import java.util.List;

public class SignInServiceImpl implements SignInService {

    private static final SignInTaskMapper signInTaskMapper = MapperUtil.getMapper(SignInTaskMapper.class);
    @Override
    public SignInTask selectTaskByStudentId(Long id) {
        return signInTaskMapper.selectTaskByStudentId(id);
    }

    @Override
    public void insertSignInTask(SignInTask signInTask) {
        List<Long> studentIds = signInTask.getStudentIds();
        SignInTaskMapper signInTaskMapperProxy = LogRecordUtil.wrap(signInTaskMapper,SignInTaskMapper.class);
        for (Long studentId : studentIds) {
            signInTaskMapperProxy.insertSignInTask(signInTask, studentId);
        }
    }

    @Override
    public void insertSignInRecord(SignInRecord signInRecord) {
        SignInTaskMapper signInTaskMapperProxy = LogRecordUtil.wrap(signInTaskMapper,SignInTaskMapper.class);
        signInTaskMapperProxy.insertSignInRecord(signInRecord);
    }

    @Override
    public void updateStateToClosed(Long teacherId) {
        signInTaskMapper.updateStateToClosed(teacherId);
    }
}
